import {createTransport, Transporter, SentMessageInfo} from "nodemailer";

let _instance: Transporter<SentMessageInfo>;

/**
 * 用于发送邮件的工具类
 */
export class NodemailerUtil {
    public static sendMail() {
        const instance = this.getInstance();
        return instance.sendMail({
            from: '939979509@qq.com', // sender address
            to: "475041821@qq.com", // list of receivers
            subject: "Hello subject", // Subject line
            text: "Hello world text?", // plain text body
            html: "<b>Hello world html?</b>", // html body
        })
    }

    private static getInstance() {
        if (!_instance) {
            _instance = createTransport({
                service: "qq", // 邮箱类型 例如service:'163'
                secure: true, // 是否使用安全连接，对https协议的
                // host: 'smtp.163.com',
                // port: 465, //qq邮件服务所占用的端口
                auth: {
                    user: "939979509@qq.com",// 开启SMTP的邮箱，发件人
                    pass: "bfjuenvgfvrjbaia"// qq授权码
                }
            })
        }
        return _instance;
    }

}